﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TpData.Layer;
using TpBaseObjects.Objects;
using System.Data;

namespace TpData.Manager {
    public class OrganisationDataManager {

        #region Members
        #endregion

        #region Load

        public static BerufstitelObject GetBerufstitel(int berufstitelKey) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.GetBerufstitel(berufstitelKey);
            }
        }

        public static List<BerufstitelObject> GetBerufstitelList() {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.GetBerufstitelList();
            }
        }

        public static FunktionsObj GetFunktion(int funktionKey) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.GetFunktion(funktionKey);
            }
        }

        public static List<FunktionsObj> GetFunktionList() {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.GetFunktionList();
            }
        }

        public static RechtsformObject GetRechtsform(int rechtsformKey) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.GetRechtsform(rechtsformKey);
            }
        }

        public static List<RechtsformObject> GetRechtsformList() {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.GetRechtsformList();
            }
        }

        public static Organisation LoadOrganisation(string name, string suchbegriff) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadOrganisation(name, suchbegriff);
            }
        }

        public static Organisation LoadOrganisation(string name, int plz) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadOrganisation(name, plz);
            }
        }

        public static Organisation LoadOrganisation(int orgKey) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadOrganisation(orgKey);
            }
        }

        public static Organisation LoadOrganisation(string suchBegriff) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadOrganisation(suchBegriff);
            }
        }

        public static DataTable LoadOrganisation() {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadOrganisationDataTable();
            }
        }

        public static List<OrganisationsShortListObj> LoadOrganisationsShortList() {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadOrganisationsShortList();
            }
        }

        public static Person GetPerson(int persKey) {
            Person retPerson = new Person();
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                List<Person> ret = dl.LoadPersons(persKey);
                if (ret != null) {
                    if (ret[0].PersKey == persKey) {
                        retPerson = ret[0];
                    }
                }
            }
            return retPerson;
        }

        public static List<Person> GetPersons() {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.LoadPersons(0);
            }
        }

        public static List<Organisation> SearchOrganisation(string orgName) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.SearchOrganisation(orgName);
            }
        }

        public static List<Organisation> SearchOrganisationStreet(string strasse) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.SearchOrganisationStreet(strasse);
            }
        }

        #endregion

        #region Save

        public static bool SaveOrganisation(Organisation myModel) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.SaveOrganisation(myModel);
            }
        }

        public static bool SavePerson(Person myModel) {
            using (OrganisationDataLayer dl = CreateOrganisationDataLayer()) {
                return dl.SavePerson(myModel);
            }
        }

        #endregion

        #region Functions

        private static OrganisationDataLayer CreateOrganisationDataLayer() {
            return (DataManager.CreateDataLayer(typeof(OrganisationDataLayer)) as OrganisationDataLayer);
        }

        #endregion

    }
}
